package com.etalk.crm.utils;

import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;

import java.io.IOException;


/**
 * @author Jordan
 */
@Configuration
@EnableAsync
public class InvokingUtils {

//	private static String url="https://e.etalk365.com:867/interface/operate/";

	private static String url="http://testee.etalk365.com:867/interface/operate/";
	/**微信发送通知*/
	private static String msgUrl="https://message.etalk365.com/";
	/**app发送消息*/
	private static String appUrl=msgUrl+"/app/product/pushmsg/";

	/**
	 * 送经验
	 * @param personId 用户id
	 * @param method 赠送渠道
	 */
	@Async
	public void addExperience(Integer personId,int method,Integer recommendedUid) throws IOException {
		String surl=url+"experience/record";
		String jsonParam="uid="+personId+"&method="+method+"&recommendedUid="+recommendedUid;
		HttpUtils.httpPost(surl, jsonParam);
		
	}
	@Async
	public void addExperience(Integer personId,int method) throws IOException {
		String surl=url+"experience/record";
		String jsonParam="uid="+personId+"&method="+method;
		HttpUtils.httpPost(surl, jsonParam);

	}

	/**
	 * 打开小E
	 * @param personId 用户id
	 */
	@Async
	public void openE(Integer personId) throws IOException {
		String surl=url+"master";
		String jsonParam="uid="+personId;
		HttpUtils.httpPost(surl, jsonParam);
		
	}

	/**
	 * 转介绍,被推荐人的状态变更
	 * @param fromUid 邀请人ID
	 * @param toUid 被邀请人ID
	 * @param status 转介绍邀请进度 1完成注册 2完成试听 3完成付费 4 30天内未退费
	 */
	@Async
	public void inviteAndStatus(Integer fromUid, Integer toUid, Integer status) throws IOException {
		String surl=url+"inviteAndStatus/record";
		String jsonParam="fromUid="+fromUid+"&toUid="+toUid+"&status="+status;
		HttpUtils.httpPost(surl, jsonParam);
//		System.out.println(surl);
//		System.out.println(result);

	}


	/**
	 * @Author James
	 * @Description
	 * @Date 10:58 2018/12/6
	 * @Param  openId 学员微信唯一标识
	 * @return
	 **/
	@Async
	public void sendWechatMsg(String openId,String jsonParam) throws IOException {
		HttpUtils.httpPost(msgUrl+"weixin/sendmsg/feedback/result?openId="+openId, jsonParam);
	}

}
